
import lessModule from "./index.module.less"
import HomePage_ModalComponent_NormalFooterComponent from "../../../../../../component/modal/component/normalFooter"
import HomePage_ModalComponent_HeaderNormalComponent from "../../../../../../component/modal/component/headerNormal"
import HomePage_ModalComponent_NormalFormComponent from "../../../../../../component/modal/component/normalForm"
import { FormInstance } from "antd/lib"
import { Form, message, } from "antd"
import { useEffect } from "react"
import { $EventBus_off, $EventBus_on } from "../../../../../../../../common/utils"
import { $Http } from "../../../../../../../../network"

// 主页-数据维护页面-定检数据维护页面-新增或编辑弹窗组件
interface componentInterface {
    change_cancel: Function
    isReview?: boolean
    sourceData: object
}
const HomePage_DataMaintenancePage_MaintenanceScheduledInspectionDataPage_AddOrEditModalComponent: React.FC<componentInterface> = (props) => {
    const [form] = Form.useForm()
    const formItemList = [
        {
            label: "安装站点",
            key: "stationName",
            type: "singleBtn",
            monitoringType: "站点",
            monitorModalName: "请选择安装站点",
            placeholder: "请选择安装站点",
            isRequire: true,
        },
        {
            key: "stationID",
            hide: true
        },
        {
            label: "巡维中心",
            key: "maintainCentre",
            type: "input",
            placeholder: "请选择安装站点",
            isDisabled: true
        },
        {
            label: "调度编号",
            key: "dispatchNumber",
            type: "input",
            placeholder: "请输入",
            isRequire: true,
        },
        {
            label: "装置厂家",
            key: "deviceFac", type: "input",
            placeholder: "请输入",
            isRequire: true,
        },
        {
            label: "装置型号",
            key: "deviceModel",
            type: "input",
            placeholder: "请输入",
            isRequire: true
        },
        {
            label: "定检周期",
            key: "inspectionCycle",
            type: "input",
            placeholder: "请输入",
            isRequire: true
        },
        {
            label: "维护时间",
            key: "maintainTime",
            // format:"YYYY/MM/DD HH:mm",
            type: "datePicker",
        },
        {
            label: "维护班组",
            key: "maintainTeam",
            type: "select",
            placeholder: "请选择",
            optionList: [{ label: "检修班组1" }, { label: "检修班组2" }, { label: "检修班组3" },],
            isRequire: true
        },
        {
            label: "维护负责人",
            key: "maintainPerson",
            type: "input",
            placeholder: "请输入",
            isRequire: true
        },
        {
            topic: "附加信息",
            type: "topic",
            width: "100%"
        },
        {
            label: "附加情况",
            key: "maintainSituation",
            type: "textArea",
            placeholder: "请输入",
            row: 3,
            width: "100%"
        },
        {
            label: "维护图片",
            key: "picture",
            type: "uploadImage",
            width: "100%"
        },
    ]
     // 广播函数数据
     const eventBusFuncData = {
        // 提交操作
        submitOperation: (data: object) => {
            form.validateFields().then((data: object) => {
                props.sourceData["type"] === "see" ? props.change_cancel() : $Http(props.sourceData["type"] === "add" ? "create" : "edit", { typeName: "数据维护/定检数据维护", ...data, ...(props.sourceData["type"] === "edit" && { id: props.sourceData["id"] }) }).then((res) => {
                    message.success(res["success"])
                    props.change_cancel()
                })
            })
        }

    }

    useEffect(() => {
        $EventBus_on(eventBusFuncData)
        return () => {
            $EventBus_off(eventBusFuncData)
        }
    }, [])


    // const change_formValue = (data: object, form: FormInstance) => {

    // }

    return (
        <div className={lessModule["homePageDataMaintenancePageMaintenanceScheduledInspectionDataPageAddOrEditModalComponent"]}>
            {
                !props.isReview && <HomePage_ModalComponent_HeaderNormalComponent name={`${props.sourceData["type"] === "add" ? "新增" : props.sourceData["type"] === "edit" && "编辑"}定检数据`} padding="15px 24px" change_cancel={props.change_cancel} />
            }

            <main className={lessModule["homePageDataMaintenancePageMaintenanceScheduledInspectionDataPageAddOrEditModalComponent-main"]}>
                <div className={lessModule["homePageDataMaintenancePageMaintenanceScheduledInspectionDataPageAddOrEditModalComponent-main__title"]}>基本信息</div>
                <HomePage_ModalComponent_NormalFormComponent form={form} type={props.sourceData["type"]} formItemList={formItemList} sourceData={props.sourceData} />
            </main>
            {
                !props.isReview && <HomePage_ModalComponent_NormalFooterComponent change_cancel={props.change_cancel} />
            }

        </div>
    )
}
export default HomePage_DataMaintenancePage_MaintenanceScheduledInspectionDataPage_AddOrEditModalComponent